//
//  main.m
//  OC06_作业
//
//  Created by dllo on 15/12/8.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Person.h"


int main(int argc, const char * argv[]) {

    /** 要求 ：
     1、创建1个包含5个字符串元素的数组；
     2、用for循环倒序输出所有元素；
     3、用for...in完成所有字符串元素的拼接(生成一个
     新的字符串)，并输出拼接好的字符串。 */
#if 0
    {
        NSArray *array = @[@"zhang", @"wang", @"li", @"liu"];
        for (NSInteger i = array.count - 1; i >= 0; i--) {
            NSLog(@"%@", array[i]);
        }
        
        
        
        
        NSString *string = [array componentsJoinedByString:@""];
        NSLog(@"%@", string);
        
   
    }
#endif
    
    /** 要求：
     1、创建1个包含5个person对象的数组(姓名用英文)；
     2、用for循环找到年龄最大的Person对象；
     3、用for...in遍历数组，把大于某个年龄的Person对象的姓名后面拼接上字符串“-brother”。 */
    
#if 0
    {
        Person *per1 = [[Person alloc] initWithName:@"wangqiang" age:80 sex:@"m"];
        Person *per2 = [[Person alloc] initWithName:@"wangyan" age:90 sex:@"w"];
        Person *per3 = [[Person alloc] initWithName:@"huoheiliu" age:23 sex:@"m"];
        Person *per4 = [[Person alloc] initWithName:@"huogaoshou" age:23 sex:@"w"];
        Person *per5 = [[Person alloc] initWithName:@"yangruidong" age:60 sex:@"w"];
        
        NSArray *array2 = @[per1, per2, per3, per4, per5];
        
        Person *maxOfAge = [[Person alloc] init];
        for (int i = 0; i < array2.count - 1; i++) {
            maxOfAge = [maxOfAge compareWithAge:array2[i]];
            
            }
        
        NSLog(@"name:%@, age:%ld, sex:%@",maxOfAge.name, maxOfAge.age, maxOfAge.sex);
        
        
        NSMutableArray *array1 = @[per1, per2, per3, per4, per5].mutableCopy;
        for (Person *per in array1) {
            if (per.age > 50) {
                per.name = [per.name stringByAppendingString:@"-brother"];
            }
            NSLog(@"name:%@, age:%ld, sex:%@",per.name, per.age, per.sex);
        }
        

    }
#endif
    
    /** 要求 ：
     1、使用第二题目中生成的数组；
     2、使用sortUsingSelector: 分别按年龄，姓名，性别进行排序，输出排序结果；
     3、使用NSSortDescriptor，按姓名进行排序。 */
#if 0
    {
        Person *per1 = [[Person alloc] initWithName:@"wangqiang" age:80 sex:@"m"];
        Person *per2 = [[Person alloc] initWithName:@"wangyan" age:90 sex:@"w"];
        Person *per3 = [[Person alloc] initWithName:@"huoheiliu" age:23 sex:@"m"];
        Person *per4 = [[Person alloc] initWithName:@"huogaoshou" age:23 sex:@"w"];
        Person *per5 = [[Person alloc] initWithName:@"yangruidong" age:60 sex:@"w"];
        
        NSArray *array1 = @[per1, per2, per3, per4, per5];
        NSArray *newArr1 = [array1 sortedArrayUsingSelector:@selector(compareWithNameUp:)];
        for (Person *per1 in newArr1) {
            NSLog(@"name:%@, age:%ld, sex:%@", per1.name, per1.age, per1.sex);
        }
        
        NSArray *newArr2 = [array1 sortedArrayUsingSelector:@selector(compareWithAgeUp:)];
        for (Person *per2 in newArr2) {
            NSLog(@"name:%@, age:%ld, sex:%@", per2.name, per2.age, per2.sex);
        }
        
        
    }
#endif
#if 0
    {
        Person *per1 = [[Person alloc] initWithName:@"wangqiang" age:80 sex:@"m"];
        Person *per2 = [[Person alloc] initWithName:@"wangyan" age:90 sex:@"w"];
        Person *per3 = [[Person alloc] initWithName:@"huoheiliu" age:23 sex:@"m"];
        Person *per4 = [[Person alloc] initWithName:@"huogaoshou" age:23 sex:@"w"];
        Person *per5 = [[Person alloc] initWithName:@"yangruidong" age:60 sex:@"w"];
        
        NSArray *array1 = @[per1, per2, per3, per4, per5];
        NSSortDescriptor *des = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
        NSArray *newArr = [array1 sortedArrayUsingDescriptors:@[des]];
        for (Person *per in newArr) {
            NSLog(@"name:%@, age:%ld, sex:%@", per.name, per.age, per.sex);
        }
                           
                           
        
    }
#endif
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}
